import { Injectable } from '@angular/core';
import {RequestUtil} from '../../util/request-util';
import {FormUtil} from '../../util/form-util';
import {MsgResult} from '../../models/msg-result';
import {Observable} from 'rxjs/Observable';
import {API} from '../../constants/constants';

@Injectable()
export class UnifiedcodeService {

  constructor(
    private requestUtil: RequestUtil,
    private formUtil: FormUtil
  ) { }
  /**
   * 获取资源目录树
   * @returns {Observable<MsgResult>}
   */
  getRescatalog(isUse): Observable<MsgResult> {
    const params = 'isUse=' + isUse;
    return this.requestUtil.get(API.getRescatalog, params);
  }
  /**
   * 保存编码
   * @param data
   * @returns {Observable<MsgResult>}
   */
  saveCode(data): Observable<MsgResult> {
    // const params = 'data = ' + encodeURI(encodeURI(JSON.stringify(data)));
    const params = 'data=' + JSON.stringify(data);
    return this.requestUtil.post(API.unifiedcode, params);
  }
  /**
   * 删除编码
   * @param id
   * @returns {Observable<MsgResult>}
   */
  deleteCode(id): Observable<MsgResult> {
    const params = 'id=' + id;
    return this.requestUtil.post(API.deleteUnifiedcode, params);
  }
}
